home *** CD-ROM | disk | FTP | other *** search
- /* C O P Y R I G H T N O T I C E : */
- /* Copyright 1986 Eric Jul and Norm Hutchinson. May not be used for any */
- /* purpose without written permission from the authors. */
-
- #ifdef xkernel
- #include "xstream.c"
- #else
-
- #include <stdio.h>
- #include <sys/time.h>
- #include "Kernel/h/assert.h"
- #include "Kernel/h/emTypes.h"
- #include "Kernel/h/kmdTypes.h"
- #include "Kernel/h/builtins.h"
- #include "Kernel/h/emeraldTypes.h"
- #include "Kernel/h/mmMsgTypes.h"
- #include "Kernel/h/emkDefs.h"
-
- extern ODP OTLookup();
- extern AbConPtr OIDOIDOIDToAbCon();
- extern OID getNextOID();
- extern CompilerLoadReqPtr CReq[];
- extern ODP KernelCheatingCreate();
-
- CodePtr inStreamCodePtr, outStreamCodePtr;
- GODP kernelStdInStream, kernelStdOutStream;
- AbConPtr inStreamAbCon, outStreamAbCon;
-
- /**********************************************************************/
-
- GODP MakeOutStream(fSock)
- int fSock;
- {
- GODP x;
- AVariable param[1];
- param[0].myAbConPtr = OIDOIDOIDToAbCon(
- OIDOfBuiltin(B_INSTAT, INTEGERINDEX), (OID) NIL,
- OIDOfBuiltin(B_INSTCT, INTEGERINDEX));
- param[0].myAddr = (DataAddr) fSock;
- x = (GODP)
- KernelCheatingCreate(getNextOID(), outStreamCodePtr->ownOID, 1, param);
- return x;
- }
-
- GODP MakeInStream(fSock)
- int fSock;
- {
- GODP x;
- AVariable param[1];
- param[0].myAbConPtr = OIDOIDOIDToAbCon(
- OIDOfBuiltin(B_INSTAT, INTEGERINDEX), (OID) NIL,
- OIDOfBuiltin(B_INSTCT, INTEGERINDEX));
- param[0].myAddr = (DataAddr) fSock;
- x = (GODP)
- KernelCheatingCreate(getNextOID(), inStreamCodePtr->ownOID, 1, param);
- return x;
- }
-
- void MakeStreamsFromSock(fSock, fInStreamPtr, fOutStreamPtr)
- int fSock;
- GODP *fInStreamPtr, *fOutStreamPtr;
- {
- KMDTrace("UserIO", 3, "Making streams for sock #%d\n", fSock);
- *fInStreamPtr = MakeInStream(fSock);
- *fOutStreamPtr = MakeOutStream(fSock);
- }
-
- /**********************************************************************/
-
- /* Kernel call */
- void GetStdOut()
- {
- currentSSP->resultBrand = VariableBrand;
- currentSSP->regs.arg1 = (int) kernelStdOutStream;
- currentSSP->regs.arg2 = (int) outStreamAbCon;
- }
-
-
- /* Kernel call */
- void GetStdIn()
- {
- currentSSP->resultBrand = VariableBrand;
- currentSSP->regs.arg1 = (int) kernelStdInStream;
- currentSSP->regs.arg2 = (int) inStreamAbCon;
- }
-
- /* Kernel call */
- void GetMyStdOut()
- {
- register int i;
- register CompilerLoadReqPtr req;
-
- for (i = 0; i < 32; i++)
- if ((CReq[i] != (CompilerLoadReqPtr) NULL)) {
- req = CReq[i];
- if (req->createdObj == currentSSP->regs.b) {
- currentSSP->resultBrand = VariableBrand;
- currentSSP->regs.arg1 = (int) req->theOutStream;
- currentSSP->regs.arg2 = (int) outStreamAbCon;
- return;
- }
- }
- /* Not found, so return kernel stdout */
- currentSSP->resultBrand = VariableBrand;
- currentSSP->regs.arg1 = (int) kernelStdOutStream;
- currentSSP->regs.arg2 = (int) outStreamAbCon;
-
- }
- /* Kernel call */
- void GetMyStdIn()
- {
- register int i;
- register CompilerLoadReqPtr req;
-
- for (i = 0; i < 32; i++)
- if ((CReq[i] != (CompilerLoadReqPtr) NULL)) {
- req = CReq[i];
- if (req->createdObj == currentSSP->regs.b) {
- currentSSP->resultBrand = VariableBrand;
- currentSSP->regs.arg1 = (int) req->theInStream;
- currentSSP->regs.arg2 = (int) inStreamAbCon;
- return;
- }
- }
-
- currentSSP->resultBrand = VariableBrand;
- currentSSP->regs.arg1 = (int) kernelStdInStream;
- currentSSP->regs.arg2 = (int) inStreamAbCon;
- }
-
- /**********************************************************************/
- /* StreamInit */
- /**********************************************************************/
- void StreamInit()
- {
- CodeODP outStreamCodeODP, inStreamCodeODP;
- CompilerLoadReqPtr req;
-
- KMDTrace("UserIO", 5, "StreamInit\n");
-
- outStreamCodeODP =
- (CodeODP) OTLookup(OIDOfBuiltin(B_INSTCT,OUTSTREAMINDEX));
- assert(NonNULL(outStreamCodeODP));
- outStreamCodePtr = outStreamCodeODP->dataPtr;
- assert(NonNULL(outStreamCodePtr));
-
- inStreamCodeODP =
- (CodeODP) OTLookup(OIDOfBuiltin(B_INSTCT,INSTREAMINDEX));
- assert(NonNULL(inStreamCodeODP));
- inStreamCodePtr = inStreamCodeODP->dataPtr;
- assert(NonNULL(inStreamCodePtr));
-
- kernelStdOutStream = MakeOutStream(fileno(stdout));
- /* Convention: InStreams that are created with sock -1 are closed when
- created. kernelStdInStream thus returns EOF on the first read
- attempt */
- kernelStdInStream = MakeInStream(-1);
-
- outStreamAbCon = OIDOIDOIDToAbCon(
- OIDOfBuiltin(B_INSTAT,OUTSTREAMINDEX), (OID) NIL,
- OIDOfBuiltin(B_INSTCT,OUTSTREAMINDEX));
- inStreamAbCon = OIDOIDOIDToAbCon(
- OIDOfBuiltin(B_INSTAT,INSTREAMINDEX), (OID) NIL,
- OIDOfBuiltin(B_INSTCT,INSTREAMINDEX));
-
- /* Create a request for kernel stdout */
- req = mNewRequest(CompilerLoad);
- req->status = Translating;
- req->sock = fileno(stdout);
- req->createdCTOID = (OID) NULL;
- req->createdObj = (GODP) NULL;
- req->theInStream = (GODP) NULL;
- req->theOutStream = kernelStdOutStream;
- req->waitingRead =
- req->waitingWrite = (SSPtr) NULL;
- req->vectorRead =
- req->vectorWrite = (VectorPtr) NULL;
- req->hangAround = TRUE;
- CReq[fileno(stdout)]= req;
- }
-
- #endif xkernel
-